// graphicsrectitem.cpp
#include "graphicsrectitem.h"
#include <QPainter>

GraphicsRectItem::GraphicsRectItem(QGraphicsItem *parent)
    : QGraphicsObject(parent), rect(-30, -10, 60, 20)  // 初始化矩形区域
{
}

QRectF GraphicsRectItem::boundingRect() const
{
    return rect;  // 返回矩形区域
}

void GraphicsRectItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    Q_UNUSED(option);
    Q_UNUSED(widget);
    painter->setBrush(Qt::red);  // 设置填充颜色
    painter->setPen(Qt::NoPen);  // 设置无边框
    painter->drawRect(rect);     // 绘制矩形
}
